package com.tjsinfo.tjsoa.common;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;


public class TreeBean {
	private String id;
	private String pname;
	private String name;
	private String text;
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getPname() {
		return pname;
	}
	public void setPname(String pname) {
		this.pname = pname;
	}
	public String getText() {
		return text;
	}
	public void setText(String text) {
		this.text = text;
	}
	
	public static String getTree(List list) {
		String tree = "";
		int size=list.size();
		String num=(String)list.get(size-1);
		list.remove(size-1);
		for (Iterator iter = list.iterator(); iter.hasNext();) {
			TreeBean bean = (TreeBean) iter.next();
			System.out.println("TreeBean:"+bean.getId());
			if (bean.getId().equals("1")) {
				tree="var num="+num+"; \r\n";
				tree += "var treeFenju2 = new xyTree.DivTree('"+"天津市粮油集团有限公司"+"');\r\n";
				System.out.println("TreeBean:"+bean.getText());
			}else {
				tree += "var node"+bean.getName()+" = new xyTree.Node('"+bean.getText()+"');\r\n";
				tree += "node"+bean.getName()+".id="+bean.getId()+";\r\n";
				if (bean.getPname().equals("1")) {
					tree += "treeFenju2.add(node"+bean.getName()+");\r\n";
				}else {
					tree += "node"+bean.getPname()+".add(node"+bean.getName()+");\r\n";
				}
			}
		}
		System.out.println(tree);
		return tree;
	}
	
	public static String getOrganizeTreeOnclick(List organizelist) {
		
		String tree = "";
		for (Iterator iter = organizelist.iterator(); iter.hasNext();) {
			TreeBean bean = (TreeBean) iter.next();
			if (bean.getId().equals("1")) {
				tree += "var treeFenju3 = new xyTree.DivTreeNormal('"+bean.getText()+"');\r\n";
			}else {
				tree += "var node"+bean.getName()+" = new xyTree.NodeNormal('"+bean.getText()+"');\r\n";
				tree += "node"+bean.getName()+".id="+bean.getId()+";\r\n";
				if (bean.getPname().equals("1")) {
					tree += "treeFenju3.add(node"+bean.getName()+");\r\n\r\n";
				}else {
					tree += "node"+bean.getPname()+".add(node"+bean.getName()+");\r\n\r\n";
				}
			}
		}
		return tree;
	}
}
